<template>
  <view>
    <template v-for="item in list" :key="item.ID">
      <wd-card :title="(userInfo.type ? '提油日期：' : '加油日期') + item.COL_0">
        <view class="justify-between items-center flex">
          <view>
            <view class="flex justify-between">
              <view>项目：</view>
              {{ item.COL_10 }}
            </view>
            <view class="flex justify-between">
              <view>油品名称：</view>
              {{ item.COL_1 }}
            </view>
            <view class="flex justify-between">
              <view>油品型号：</view>
              {{ item.COL_2 }}
            </view>
            <view class="flex justify-between">
              <view>{{ userInfo.type ? '提油' : '加油' }}数量：</view>
              {{ item.COL_3 }} {{ userInfo.type ? '吨' : '升' }}
            </view>
            <view class="flex items-center mt-4 flex-wrap gap-1">
              单据：
              <wd-img v-for="(v,index) in item.imgList" :key="index" :width="50" :height="50" :src="'https://miniapp.zhangmushiye.com/' + v.url" @click="previewImage(item,index)"/>
            </view>
          </view>
          <view class="">
            <wd-button v-if="item.settlement_type != 1" size="small" type="warning" @click="goEdit(item)">编辑</wd-button>
          </view>
        </view>
      </wd-card>
    </template>
  </view>
</template>

<script setup>
import DemoApi from '@/api/DemoApi'
import router from "@/router";

const { userInfo } = storeToRefs(useAuthStore())

const list = ref([])
const params = {
  mobile: userInfo.value.COL_1
}

onShow(() => {
  getList()
})
const getList = () => {
  if (userInfo.value.type) {
    DemoApi.duizhanghistory(params).then((res) => {
      list.value = res.data.map((item) => {
        const data = JSON.parse(JSON.stringify(item))
        item.COL_10 = data.COL_1
        item.COL_1 = data.COL_2
        item.COL_2 = data.COL_3
        item.COL_3 = data.COL_6
        if (item.COL_15) {
          item.COL_15 = JSON.parse(item.COL_15)
          item.imgList = item.COL_15
        }
        return item
      })
    })
  } else {
    DemoApi.history(params).then((res) => {
      list.value = res.data.map((item) => {
        if (item.COL_19) {
          item.COL_19 = JSON.parse(item.COL_19)
          item.imgList = item.COL_19
        }
        return item
      })
    })
  }
}
const goEdit = (item) => {
  if (userInfo.value.type) {
    uni.navigateTo({
      url: `/pages/publish/Duizhang?query=${encodeURIComponent(JSON.stringify(item))}`
    })
  } else {
    uni.navigateTo({
      url: `/pages/publish/Publish?query=${encodeURIComponent(JSON.stringify(item))}`
    })
  }
}

const previewImage = (item, index) => {
  uni.previewImage({
    current: index,
    urls: item.imgList.map((item) => {
      return 'https://miniapp.zhangmushiye.com/' + item.url.msg
    })
  })
}
</script>

<style lang="scss"></style>
